//
//  DHCustomImageView.m
//  YDAPP
//
//  Created by tyxd on 17/3/1.
//  Copyright © 2017年 TYXD. All rights reserved.
//

#import "DHCustomImageView.h"

@implementation DHCustomImageView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.userInteractionEnabled = YES; 
        
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
//        btn.frame = CGRectMake(frame.size.width - 8, -8, 16, 16);
        btn.layer.cornerRadius = 8;
        btn.clipsToBounds = YES;
        [btn setImage:[UIImage imageNamed:@"pop_icon_close"] forState:UIControlStateNormal];
        btn.contentEdgeInsets = UIEdgeInsetsMake(3, 3, 3, 3);
        btn.backgroundColor = ButtonBackGroundColor;
        [self addSubview:btn];
        self.deleteBtn = btn;
        
        [btn mas_remakeConstraints:^(MASConstraintMaker *make) {
           
            make.top.mas_equalTo(self).offset(-8);
            make.left.mas_equalTo(self.mas_right).offset(-8);
            make.height.width.mas_equalTo(16);
            
        }];
    }
    return self;
}

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
    UIView *view = [super hitTest:point withEvent:event];
    if (view == nil) {
        CGPoint tempoint = [self.deleteBtn convertPoint:point fromView:self];
        if (CGRectContainsPoint(self.deleteBtn.bounds, tempoint))
        {
            view = self.deleteBtn;
        }
    }
    return view;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
